<template>
  <div style=" width: 99%; margin: auto;">
    <h2>接受监督检查情况</h2>
    <el-form :model="postForm" ref="postFormRef" :rules="postRules" size="default" label-width="140px">
      <h3>年度检查</h3>
      <el-row style="margin-top: 15px;" :gutter="20"  v-for="(item,index) in postForm.checkList" :key="index">

        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="socialOrganizationEvaluation" label="检查年度">
              <el-input disabled v-model="postForm.checkList[index].inspectYear"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="rectificationConclusion" label="年检结论">
            <el-select clearable  v-model="postForm.checkList[index].rectificationConclusion" placeholder="请选择"
                       style="width: 100%;">
              <el-option
                v-for="dict in annualOptions"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="rectificationSituation" label="整改情况">
            <el-select clearable  v-model="postForm.checkList[index].rectificationSituation" placeholder="请选择" style="width: 100%;">
              <el-option
                v-for="dict in situationOptions"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <h3>社会组织评估</h3>
      <el-row style="margin-top: 15px;" :gutter="20">
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="socialOrganizationEvaluation" label="是否参评">
            <el-radio-group v-model="postForm.socialOrganizationEvaluation" @change="socialOrganizationEvaluationChange">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;" v-show="postForm.socialOrganizationEvaluation == 1">
          <el-form-item prop="socialOrganizationEvaluationResult" label="评估结果">
            <el-select clearable  v-model="postForm.socialOrganizationEvaluationResult" placeholder="请选择"
                       style="width: 100%;">
              <el-option
                v-for="dict in levelOptions"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;" v-show="postForm.socialOrganizationEvaluation == 1">
          <el-form-item prop="socialOrganizationEvaluationValidityPeriod" label="有效期至">
            <el-date-picker
              v-model="postForm.socialOrganizationEvaluationValidityPeriod"
              type="date"
              style="width: 100%;"
              value-format="YYYY-MM-DD"
              placeholder="有效期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <h3>获得税收优惠资格情况</h3>
      <el-row style="margin-top: 15px;" :gutter="20">
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="eligibilityTaxIncentivesTimeState" label="公益性捐赠税前扣除资格">
            <el-radio-group v-model="postForm.eligibilityTaxIncentivesTimeState">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;" v-if="postForm.eligibilityTaxIncentivesTimeState == '1'">
          <el-form-item prop="eligibilityTaxIncentivesTime" label="获得税收优惠资格时间">
            <el-date-picker
              style="width: 100%;"

              v-model="postForm.eligibilityTaxIncentivesTime"
              value-format="YYYY-MM-DD"
              type="date"
              placeholder="获得税收优惠资格时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="organizationalExemptionEligibilityTimeState" label="非营利组织免税资格">
            <el-radio-group v-model="postForm.organizationalExemptionEligibilityTimeState">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;"  v-if="postForm.organizationalExemptionEligibilityTimeState == '1'">
          <el-form-item prop="organizationalExemptionEligibilityTime" label="资格时间">
            <el-date-picker
              style="width: 100%;"
              v-model="postForm.organizationalExemptionEligibilityTime"
              value-format="YYYY-MM-DD"
              type="date"
              placeholder="资格时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <h3>行政处罚</h3>
      <el-row style="margin-top: 15px;" :gutter="20">
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="administrativePenalty" label="是否受到过行政处罚">
            <el-radio-group v-model="postForm.administrativePenalty">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="administrativePenaltyTime" label="行政处罚时间">
            <el-date-picker
              style="width: 100%;"
              v-model="postForm.administrativePenaltyTime"
              type="date"
              value-format="YYYY-MM-DD"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="administrativePenaltyType" label="行政处罚种类">
            <el-select clearable  v-model="postForm.administrativePenaltyType" placeholder="请选择" style="width: 100%;">
              <el-option
                v-for="dict in administrativePenaltyOptions"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="administrativePenaltyOffice" label="行政处罚实施机关">
            <el-input placeholder="请完善" v-model="postForm.administrativePenaltyOffice"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="illegalBehavior" label="违法行为">
            <el-input placeholder="请完善" v-model="postForm.illegalBehavior"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <h3>信用信息管理情况</h3>
      <el-row style="margin-top: 15px;" :gutter="20">
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="activityXceptionIrectory" label="是否被列入活动异常名录">
            <el-radio-group disabled v-model="postForm.activityXceptionIrectory">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="seriousIllegalBehavior" label="是否被列入严重违法失信名单">
            <el-radio-group disabled v-model="postForm.seriousIllegalBehavior">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-bottom: 15px;">
          <el-form-item prop="listedTime" label="列入时间">
            <el-date-picker
              disabled
              style="width: 100%;"
              v-model="postForm.listedTime"
              type="date"
              value-format="YYYY-MM-DD"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { getDictByCode, getTableInfoByPage, mfSaveSupervision } from '@/views/yearCheck/ykb/mf/mf'

export default {
  data() {
    return {
      situationOptions: undefined,
      administrativePenaltyOptions: undefined,
      annualOptions: undefined,
      levelOptions:undefined,
      postForm: {
        id: '',
        eligibilityTaxIncentivesTimeState: '',
        organizationalExemptionEligibilityTimeState: '',
        activityXceptionIrectory: '',//是否列入活动异常名录1-是 2-否 0-未知
        administrativePenalty: '',//是否受到过行政处罚1-是 2-否 0-未知
        administrativePenaltyOffice: '',//行政处罚机关
        administrativePenaltyTime: '',//($date-time)行政处罚时间
        administrativePenaltyType: '',//行政处罚种类
        checkList: [{
          inspectYear: '',//检查年度
          rectificationConclusion: '',//年检结论
          rectificationSituation: ''//整改情况
        }, {
          inspectYear: '',//检查年度
          rectificationConclusion: '',//年检结论
          rectificationSituation: ''//整改情况
        }, {
          inspectYear: '',//检查年度
          rectificationConclusion: '',//年检结论
          rectificationSituation: ''//整改情况
        }],
        creditCode: localStorage.getItem('creditCode'),//统一社会信用代码
        eligibilityTaxIncentivesTime: '',//($date-time)获得税收优惠资格时间
        examineYear: localStorage.getItem('examineYear'),//备案年度
        illegalBehavior: '',//违法行为
        listedTime: '',//($date-time)列入时间
        organizationBaseId: '1',//社团组织id
        organizationalExemptionEligibilityTime: '',//($date-time)非营利组织免税资格时间
        seriousIllegalBehavior: '',//是否列入严重违法失信名单1-是 2-否 0-未知
        socialOrganizationEvaluation: '',//是否参加社会组织评估1-是 2-否 0-未知
        socialOrganizationEvaluationResult: '',//社会组织评估结果
        socialOrganizationEvaluationValidityPeriod: ''//社会组织评估有效期
      },
      postRules: {
        socialOrganizationEvaluation: [{ required: true, message: '请完善', trigger: 'blur' }],
        // socialOrganizationEvaluationResult: [{ required: true, message: '请完善', trigger: 'blur' }],
        // socialOrganizationEvaluationValidityPeriod: [{ required: true, message: '请完善', trigger: 'blur' }],
        administrativePenalty: [{ required: true, message: '请完善', trigger: 'blur' }],
        organizationalExemptionEligibilityTimeState: [{ required: true, message: '请完善', trigger: 'blur' }],
        eligibilityTaxIncentivesTimeState: [{ required: true, message: '请完善', trigger: 'blur' }]
      }
    }
  },

  created() {

  },
  methods: {
    socialOrganizationEvaluationChange(e){
      if(e == 1){

      }else{
        this.postForm.socialOrganizationEvaluationResult = '';
        this.postForm.socialOrganizationEvaluationValidityPeriod = '';
      }
    },
    postInfo() {
      this.$refs.postFormRef.validate(valid => {
        if (valid) {
          this.postForm.creditCode = localStorage.getItem('creditCode')
          this.postForm.examineYear = localStorage.getItem('examineYear')
          this.postForm.organizationBaseId = '1'
          mfSaveSupervision(this.postForm).then(response => {
            this.$message({
              message: '保存接受监督检查情况成功！',
              type: 'success'
            })
            this.getInfo()
          })
        } else {
          this.$message({
            message: '请填写完整！',
            type: 'error'
          })
        }
      })

    },
    getInfo() {
      this.getDict()
      getTableInfoByPage(7).then(response => {
        this.postForm = JSON.parse(JSON.stringify(response.data).replace(/null/g, '""'))
        this.postForm.socialOrganizationEvaluation += ''
        this.postForm.seriousIllegalBehavior += ''
        this.postForm.activityXceptionIrectory += ''
        this.postForm.administrativePenalty += ''
        if (this.postForm.eligibilityTaxIncentivesTimeState != null) {
          this.postForm.eligibilityTaxIncentivesTimeState += ''
        }
        if (this.postForm.organizationalExemptionEligibilityTimeState != null) {
          this.postForm.organizationalExemptionEligibilityTimeState += ''
        }
        if (this.postForm.activityXceptionIrectory == ''){
          this.postForm.activityXceptionIrectory = '2';
        }
        if (this.postForm.seriousIllegalBehavior == ''){
          this.postForm.seriousIllegalBehavior = '2';
        }
        if (this.postForm.checkList == null || this.postForm.checkList == '') {
          this.postForm.checkList = []
          let currentYear = localStorage.getItem('examineYear')
          this.postForm.checkList.push({
            inspectYear: currentYear - 2,//检查年度
            rectificationConclusion: '',//年检结论
            rectificationSituation: ''//整改情况
          })
          this.postForm.checkList.push({
            inspectYear: currentYear - 1,//检查年度
            rectificationConclusion: '',//年检结论
            rectificationSituation: ''//整改情况
          })
        } else if (this.postForm.checkList.length == 1) {
          let currentYear = localStorage.getItem('examineYear')
          this.postForm.checkList.push({
            inspectYear: currentYear - 1,//检查年度
            rectificationConclusion: '',//年检结论
            rectificationSituation: ''//整改情况
          })
        }
      })
    },
    getDict() {
      getDictByCode('situation').then(response => {
        this.situationOptions = response.data
      })
      getDictByCode('annual').then(response => {
        this.annualOptions = response.data
      })
      getDictByCode('level').then(response => {
        this.levelOptions = response.data
      })

      getDictByCode('administrativePenalty').then(response => {
        this.administrativePenaltyOptions = response.data
      })
    }
  }
}
</script>
<style scoped lang="scss">
.el-table {
  --el-table-row-hover-bg-color: rgba(39, 137, 238, 0.1);
  --el-table-border-color:#e0e5f0;
}
:deep(.el-card.is-always-shadow) {
  box-shadow: 0 1px 14px 0 rgba(209, 224, 239, 0.6)
}

/* 拉框选中 */
.el-select-dropdown__item {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

/* 鼠标经过下拉框 */
.el-select-dropdown__item:hover {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

.el-select-dropdown__item.selected {
  color: #2789EE;
}
.app-container {
  margin-top: 40px;
  margin-left: 15%;
  width: 70%;
}

.div-bg {
  width: 100%;
  background: #F0F0F0;
  height: 10px;
}

.box-card {
  width: 100%;
  margin-top: 20px;
  padding: 20px;
}

.el-col {
  padding-left: 5px;
}

.divider-title {
  font-weight: bold;
  font-size: 18px;
}

.custom-select .el-select-dropdown {
  max-height: 600px; /* 设置为你想要的高度 */
  overflow: auto; /* 添加滚动条 */
}

table {
  border-collapse: collapse; /* 确保表格的边框合并为单一边框 */
  width: 100%; /* 表格宽度 */
}

td {
  border: 1px solid #ababab; /* 设置单线边框 */
  padding: 6px; /* 单元格内边距 */
}

.el-form-item {
  margin-bottom: 0px;
}

:deep(.el-form-item__label) {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  text-align: right;
  height: 32px;
  line-height: 16px;
}
</style>
